 package client;

 import com.alibaba.druid.pool.DruidPooledConnection;
 import configs.ServerConfig;
 import constants.ServerConstants;
 import database.DatabaseConnection;
 import handling.cashshop.CashShopServer;
 import handling.channel.ChannelServer;
 import handling.login.LoginServer;
 import handling.login.handler.AutoRegister;
import handling.opcode.RecvPacketOpcode;
 import handling.world.PartyOperation;
 import handling.world.WorldBuddyService;
 import handling.world.WorldFamilyService;
 import handling.world.WorldFindService;
 import handling.world.WorldGuildService;
 import handling.world.WorldMessengerService;
 import handling.world.WorldPartyService;
 import handling.world.family.MapleFamilyCharacter;
 import handling.world.guild.MapleGuildCharacter;
 import handling.world.messenger.MapleMessengerCharacter;
 import handling.world.party.MapleParty;
 import handling.world.party.MaplePartyCharacter;
 import io.netty.channel.Channel;
 import io.netty.util.AttributeKey;
 import java.io.Serializable;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.script.ScriptEngine;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import scripting.item.ItemActionManager;
 import scripting.item.ItemScriptManager;
 import scripting.npc.NPCConversationManager;
 import scripting.npc.NPCScriptManager;
 import scripting.quest.QuestActionManager;
 import scripting.quest.QuestScriptManager;
 import server.CharacterCardFactory;
 import server.Timer;
 import server.maps.MapleMap;
 import server.quest.MapleQuest;
 import server.shops.IMaplePlayerShop;
 import tools.DebugUI;
 import tools.MapleAESOFB;
 import tools.MaplePacketCreator;
 import tools.Pair;
 import tools.Randomizer;
 import tools.Triple;
 import tools.TripleDESCipher;
 import tools.packet.LoginPacket;

 public class MapleClient implements Serializable {
    /*   53 */   private static final Logger log_autofix = LogManager.getLogger("AutoFixLog");

       public static final byte LOGIN_NOTLOGGEDIN = 0;

       public static final byte LOGIN_SERVER_TRANSITION = 1;

       public static final byte LOGIN_LOGGEDIN = 2;

       public static final byte CHANGE_CHANNEL = 3;

       public static final byte ENTERING_PIN = 4;

       public static final byte PIN_CORRECT = 5;

       public static final byte LOGIN_CS_LOGGEDIN = 6;

    /*   56 */   public static final AttributeKey<MapleClient> CLIENT_KEY = AttributeKey.newInstance("Client");

    /*   57 */   private static final Logger log = LogManager.getLogger(MapleClient.class);

       private static final long serialVersionUID = 9179541993413738569L;

    /*   59 */   private static final Lock login_mutex = new ReentrantLock(true);

    /*   60 */   private final transient Lock mutex = new ReentrantLock(true);

    /*   61 */   private final transient Lock npc_mutex = new ReentrantLock();

    /*   62 */   private final transient long lastChatServerPing = 0L;

    /*   63 */   private final transient List<Integer> allowedChar = new LinkedList<>();

    /*   64 */   private final transient Map<String, ScriptEngine> engines = new HashMap<>();

    /*   65 */   private final Map<Integer, Pair<Integer, Short>> charInfo = new LinkedHashMap<>();

    /*   66 */   private final List<String> proesslist = new ArrayList<>();

    /*   67 */   public transient short loginAttempt = 0;

       private transient MapleAESOFB send;

       private transient MapleAESOFB receive;

       private transient Channel session;

       private MapleCharacter player;

    /*   71 */   private int channel = 1, accId = -1;

       private int world;

       private int birthday;

    /*   72 */   private int charslots = ServerConfig.CHANNEL_PLAYER_MAXCHARACTERS;

    /*   73 */   private int cardslots = 3;

       private boolean loggedIn = false;

       private boolean serverTransition = false;

    /*   75 */   private transient Calendar tempban = null;

       private String accountName;

    /*   77 */   private transient long lastPong = 0L;

    /*   78 */   private transient long lastPing = 0L;

    /*   79 */   private transient long lastChatServerPong = 0L;

       private boolean monitored = false;

       private boolean receiving = true;

       private int gm;

    /*   82 */   private byte greason = 1;

    /*   82 */   private byte gender = -1;

    /*   83 */   private transient String mac = "00-00-00-00-00-00";

    /*   84 */   private transient List<String> maclist = new LinkedList<>();

    /*   85 */   private transient ScheduledFuture<?> idleTask = null;

       private transient String secondPassword;

       private transient String salt2;

    /*   86 */   private transient String tempIP = "";

    /*   87 */   private long lastNpcClick = 0L;

       private long sessionId;

    /*   88 */   private byte loginattempt = 0;

       private DebugUI debugWindow;

    /*   90 */   private Triple<String, String, Boolean> tempinfo = null;

    /*   91 */   private final ReentrantReadWriteLock disconnectLock = new ReentrantReadWriteLock();

    /*   92 */   public Map<Integer, Integer> mEncryptedOpcode = new LinkedHashMap<>();

       private transient ScheduledFuture<?> pingTask;

       private boolean isDisconnect;

    /*   95 */   private int timeoutCount = 0;

    /*   96 */   private final Map<String, String> keyValue = new HashMap<>();

       private boolean changed_keyValue = false;

       public MapleClient(MapleAESOFB send, MapleAESOFB receive, Channel session) {
        /*  104 */     this.send = send;
        /*  105 */     this.receive = receive;
        /*  106 */     this.session = session;
           }

       public static byte unban(String charname) {
        /*  110 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  111 */         PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?")) {
                   int accid;
            /*  112 */       ps.setString(1, charname);
            /*  114 */       try (ResultSet rs = ps.executeQuery()) {
                /*  115 */         if (!rs.next())
                    /*  116 */           return -1;
                /*  118 */         accid = rs.getInt(1);
                       }
            /*  121 */       try (PreparedStatement psu = con.prepareStatement("UPDATE accounts SET banned = 0, banreason = '' WHERE id = ?")) {
                /*  122 */         psu.setInt(1, accid);
                /*  123 */         psu.executeUpdate();
                       }
            /*  126 */     } catch (SQLException e) {
            /*  127 */       log.error("Error while unbanning", e);
            /*  128 */       return -2;
                 }
        /*  130 */     return 0;
           }

       public static String getLogMessage(MapleClient cfor, String message) {
        /*  134 */     return getLogMessage(cfor, message, new Object[0]);
           }

       public static String getLogMessage(MapleCharacter cfor, String message) {
        /*  138 */     return getLogMessage((cfor == null) ? null : cfor.getClient(), message);
           }

       public static String getLogMessage(MapleCharacter cfor, String message, Object... parms) {
        /*  142 */     return getLogMessage((cfor == null) ? null : cfor.getClient(), message, parms);
           }

       public static String getLogMessage(MapleClient cfor, String message, Object... parms) {
        /*  146 */     StringBuilder builder = new StringBuilder();
        /*  147 */     if (cfor != null) {
            /*  148 */       if (cfor.getPlayer() != null) {
                /*  149 */         builder.append("<");
                /*  150 */         builder.append(MapleCharacterUtil.makeMapleReadable(cfor.getPlayer().getName()));
                /*  151 */         builder.append(" (角色ID: ");
                /*  152 */         builder.append(cfor.getPlayer().getId());
                /*  153 */         builder.append(")> ");
                       }
            /*  155 */       if (cfor.getAccountName() != null) {
                /*  156 */         builder.append("(账号: ");
                /*  157 */         builder.append(cfor.getAccountName());
                /*  158 */         builder.append(") ");
                       }
                 }
        /*  161 */     builder.append(message);
        /*  163 */     for (Object parm : parms) {
            /*  164 */       int start = builder.indexOf("{}");
            /*  165 */       builder.replace(start, start + 2, parm.toString());
                 }
        /*  167 */     return builder.toString();
           }

       public static int findAccIdForCharacterName(String charName) {
        /*  171 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  172 */         PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?")) {
            /*  173 */       ps.setString(1, charName);
            /*  174 */       ResultSet rs = ps.executeQuery();
            /*  175 */       int ret = -1;
            /*  176 */       if (rs.next())
                /*  177 */         ret = rs.getInt("accountid");
            /*  179 */       return ret;
            /*  181 */     } catch (SQLException e) {
            /*  182 */       log.error("findAccIdForCharacterName SQL error", e);
            /*  184 */       return -1;
                 }
           }

       public static byte unbanIPMacs(String charname) {
        /*  188 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            /*  189 */       PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
            /*  190 */       ps.setString(1, charname);
            /*  191 */       ResultSet rs = ps.executeQuery();
            /*  192 */       if (!rs.next()) {
                /*  193 */         rs.close();
                /*  194 */         ps.close();
                /*  195 */         return -1;
                       }
            /*  197 */       int accid = rs.getInt(1);
            /*  198 */       rs.close();
            /*  199 */       ps.close();
            /*  200 */       ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
            /*  201 */       ps.setInt(1, accid);
            /*  202 */       rs = ps.executeQuery();
            /*  203 */       if (!rs.next()) {
                /*  204 */         rs.close();
                /*  205 */         ps.close();
                /*  206 */         return -1;
                       }
            /*  208 */       String sessionIP = rs.getString("sessionIP");
            /*  209 */       String macs = rs.getString("macs");
            /*  210 */       rs.close();
            /*  211 */       ps.close();
            /*  212 */       byte ret = 0;
            /*  213 */       if (sessionIP != null) {
                /*  214 */         PreparedStatement psa = con.prepareStatement("DELETE FROM ipbans WHERE ip LIKE ?");
                /*  215 */         psa.setString(1, sessionIP);
                /*  216 */         psa.execute();
                /*  217 */         psa.close();
                /*  218 */         ret = (byte)(ret + 1);
                       }
            /*  220 */       if (macs != null) {
                /*  221 */         String[] macz = macs.split(", ");
                /*  222 */         for (String mac : macz) {
                    /*  223 */           if (!mac.equals("")) {
                        /*  224 */             PreparedStatement psa = con.prepareStatement("DELETE FROM macbans WHERE mac = ?");
                        /*  225 */             psa.setString(1, mac);
                        /*  226 */             psa.execute();
                        /*  227 */             psa.close();
                                   }
                             }
                /*  230 */         ret = (byte)(ret + 1);
                       }
            /*  232 */       return ret;
            /*  233 */     } catch (SQLException e) {
            /*  234 */       log.error("Error while unbanning", e);
            /*  235 */       return -2;
                 }
           }

       public static byte unHellban(String charname) {
        /*  240 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            /*  241 */       PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
            /*  242 */       ps.setString(1, charname);
            /*  243 */       ResultSet rs = ps.executeQuery();
            /*  244 */       if (!rs.next()) {
                /*  245 */         rs.close();
                /*  246 */         ps.close();
                /*  247 */         return -1;
                       }
            /*  249 */       int accid = rs.getInt(1);
            /*  250 */       rs.close();
            /*  251 */       ps.close();
            /*  252 */       ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
            /*  253 */       ps.setInt(1, accid);
            /*  254 */       rs = ps.executeQuery();
            /*  255 */       if (!rs.next()) {
                /*  256 */         rs.close();
                /*  257 */         ps.close();
                /*  258 */         return -1;
                       }
            /*  260 */       String sessionIP = rs.getString("sessionIP");
            /*  261 */       String email = rs.getString("email");
            /*  262 */       rs.close();
            /*  263 */       ps.close();
            /*  264 */       ps = con.prepareStatement("UPDATE accounts SET banned = 0, banreason = '' WHERE email = ?" + ((sessionIP == null) ? "" : " OR sessionIP = ?"));
            /*  265 */       ps.setString(1, email);
            /*  266 */       if (sessionIP != null)
                /*  267 */         ps.setString(2, sessionIP);
            /*  269 */       ps.execute();
            /*  270 */       ps.close();
            /*  271 */       return 0;
            /*  272 */     } catch (SQLException e) {
            /*  273 */       log.error("Error while unbanning", e);
            /*  274 */       return -2;
                 }
           }

       public static String getAccInfo(String accname, boolean admin) {
        /*  279 */     StringBuilder ret = new StringBuilder("帐号 " + accname + " 的信息 -");
        /*  280 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            /*  281 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE name = ?");
            /*  282 */       ps.setString(1, accname);
            /*  283 */       ResultSet rs = ps.executeQuery();
            /*  284 */       if (rs.next()) {
                /*  285 */         int banned = rs.getInt("banned");
                /*  286 */         ret.append(" 状态: ");
                /*  287 */         ret.append((banned > 0) ? "已封" : "正常");
                /*  288 */         ret.append(" 封号理由: ");
                /*  289 */         ret.append((banned > 0) ? rs.getString("banreason") : "(无描述)");
                /*  290 */         if (admin) {
                    /*  291 */           ret.append(" 点卷: ");
                    /*  292 */           ret.append(rs.getInt("ACash"));
                    /*  293 */           ret.append(" 抵用卷: ");
                    /*  294 */           ret.append(rs.getInt("mPoints"));
                             }
                       }
            /*  297 */       rs.close();
            /*  298 */       ps.close();
            /*  299 */     } catch (SQLException ex) {
            /*  300 */       log.error("获取玩家封号理由信息出错", ex);
                 }
        /*  302 */     return ret.toString();
           }

       public static String getAccInfoByName(String charname, boolean admin) {
        try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            try (PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?")) {
                ps.setString(1, charname);
                int accid;
                try (ResultSet rs = ps.executeQuery()) {
                    if (!rs.next()) {
                        return null;
                    }
                    accid = rs.getInt(1);
                }
                try (PreparedStatement psu = con.prepareStatement("SELECT * FROM accounts WHERE id = ?")) {
                    psu.setInt(1, accid);
                    try (ResultSet rs = ps.executeQuery()) {
                        if (!rs.next()) {
                            return null;
                        }

                        StringBuilder ret = new StringBuilder("玩家 " + charname + " 的帐号信息 -");
                        int banned = rs.getInt("banned");
                        if (admin) {
                            ret.append(" 账号: ");
                            ret.append(rs.getString("name"));
                        }
                        ret.append(" 状态: ");
                        ret.append(banned > 0 ? "已封" : "正常");
                        ret.append(" 封号理由: ");
                        ret.append(banned > 0 ? rs.getString("banreason") : "(无描述)");
                        return ret.toString();
                    }
                }
            }
        } catch (SQLException ex) {
            log.error("获取玩家封号理由信息出错", ex);
            return null;
        }
           }

       public synchronized MapleAESOFB getReceiveCrypto() {
        /*  344 */     return this.receive;
           }

       public synchronized MapleAESOFB getSendCrypto() {
        /*  348 */     return this.send;
           }

       public final void announce(byte[] array) {
        /*  352 */     this.session.writeAndFlush(array);
           }

       public final void sendEnableActions() {
        /*  356 */     this.session.writeAndFlush(MaplePacketCreator.enableActions());
           }

       public synchronized Channel getSession() {
        /*  360 */     return this.session;
           }

       public long getSessionId() {
        /*  364 */     return this.sessionId;
           }

       public void setSessionId(long sessionId) {
        /*  368 */     this.sessionId = sessionId;
           }

       public void StartWindow() {
        /*  372 */     if (this.debugWindow != null) {
            /*  373 */       this.debugWindow.setVisible(false);
            /*  374 */       this.debugWindow = null;
                 }
        /*  376 */     this.debugWindow = new DebugUI();
        /*  377 */     this.debugWindow.setVisible(true);
        /*  378 */     this.debugWindow.setC(this);
           }

       public Lock getLock() {
        /*  382 */     return this.mutex;
           }

       public Lock getNPCLock() {
        /*  386 */     return this.npc_mutex;
           }

       public MapleCharacter getPlayer() {
        /*  390 */     return this.player;
           }

       public void setPlayer(MapleCharacter player) {
        /*  394 */     this.player = player;
           }

       public void createdChar(int id) {
        /*  398 */     this.allowedChar.add(Integer.valueOf(id));
           }

       public boolean login_Auth(int id) {
        /*  402 */     return this.allowedChar.contains(Integer.valueOf(id));
           }

       public List<MapleCharacter> loadCharacters(int serverId) {
        /*  406 */     List<MapleCharacter> chars = new LinkedList<>();
        /*  407 */     Map<Integer, CardData> cards = CharacterCardFactory.getInstance().loadCharacterCards(this.accId, serverId);
        /*  408 */     for (CharNameAndId cni : loadCharactersInternal(serverId)) {
            /*  409 */       MapleCharacter chr = MapleCharacter.loadCharFromDB(cni.id, this, false, cards);
            /*  410 */       chars.add(chr);
            /*  411 */       this.charInfo.put(Integer.valueOf(chr.getId()), new Pair(Integer.valueOf(chr.getLevel()), Short.valueOf(chr.getJob())));
            /*  412 */       if (!login_Auth(chr.getId()))
                /*  413 */         this.allowedChar.add(Integer.valueOf(chr.getId()));
                 }
        /*  416 */     return chars;
           }

       public void updateCharacterCards(Map<Integer, Integer> cids) {
        /*  420 */     if (this.charInfo.isEmpty())
                   return;
        /*  423 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            /*  424 */       try (PreparedStatement ps = con.prepareStatement("DELETE FROM `character_cards` WHERE `accid` = ?")) {
                /*  425 */         ps.setInt(1, this.accId);
                /*  426 */         ps.executeUpdate();
                       }
            /*  429 */       try (PreparedStatement psu = con.prepareStatement("INSERT INTO `character_cards` (accid, worldid, characterid, position) VALUES (?, ?, ?, ?)")) {
                /*  430 */         for (Map.Entry<Integer, Integer> ii : cids.entrySet()) {
                    /*  431 */           Pair<Integer, Short> info = this.charInfo.get(ii.getValue());
                    /*  432 */           if (info == null || ((Integer)ii.getValue()).intValue() == 0 || !CharacterCardFactory.getInstance().canHaveCard(((Integer)info.getLeft()).intValue(), ((Short)info.getRight()).shortValue()))
                                     continue;
                    /*  435 */           psu.setInt(1, this.accId);
                    /*  436 */           psu.setInt(2, this.world);
                    /*  437 */           psu.setInt(3, ((Integer)ii.getValue()).intValue());
                    /*  438 */           psu.setInt(4, ((Integer)ii.getKey()).intValue());
                    /*  439 */           psu.executeUpdate();
                             }
                       }
            /*  442 */     } catch (SQLException e) {
            /*  443 */       log.error("Failed to update character cards. Reason:", e);
                 }
           }

       public int getCharacterJob(int cid) {
        /*  448 */     if (this.charInfo.containsKey(Integer.valueOf(cid)))
            /*  449 */       return ((Short)((Pair)this.charInfo.get(Integer.valueOf(cid))).getRight()).shortValue();
        /*  451 */     return -1;
           }

       public boolean canMakeCharacter(int serverId) {
        /*  455 */     return (loadCharactersSize(serverId) < getAccCharSlots());
           }

       public List<String> loadCharacterNames(int serverId) {
        /*  459 */     List<String> chars = new LinkedList<>();
        /*  460 */     for (CharNameAndId cni : loadCharactersInternal(serverId))
            /*  461 */       chars.add(cni.name);
        /*  463 */     return chars;
           }

       private List<CharNameAndId> loadCharactersInternal(int serverId) {
        /*  467 */     List<CharNameAndId> chars = new LinkedList<>();
        /*  468 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  469 */         PreparedStatement ps = con.prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ? ORDER BY position, id")) {
            /*  470 */       ps.setInt(1, this.accId);
            /*  471 */       ps.setInt(2, serverId);
            /*  473 */       try (ResultSet rs = ps.executeQuery()) {
                /*  474 */         while (rs.next()) {
                    /*  475 */           chars.add(new CharNameAndId(rs.getString("name"), rs.getInt("id")));
                    /*  476 */           LoginServer.getLoginAuth(rs.getInt("id"));
                             }
                       }
            /*  480 */     } catch (SQLException e) {
            /*  481 */       log.error("error loading characters internal", e);
                 }
        /*  483 */     return chars;
           }

       public int loadCharactersSize(int serverId) {
        /*  490 */     int chars = 0;
        /*  491 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  492 */         PreparedStatement ps = con.prepareStatement("SELECT count(*) FROM characters WHERE accountid = ? AND world = ?")) {
            /*  493 */       ps.setInt(1, this.accId);
            /*  494 */       ps.setInt(2, serverId);
            /*  496 */       try (ResultSet rs = ps.executeQuery()) {
                /*  497 */         if (rs.next())
                    /*  498 */           chars = rs.getInt(1);
                       }
            /*  502 */     } catch (SQLException e) {
            /*  503 */       log.error("error loading characters size", e);
                 }
        /*  505 */     return chars;
           }

       public boolean isLoggedIn() {
        /*  509 */     return (this.loggedIn && this.accId >= 0);
           }

       private Calendar getTempBanCalendar(ResultSet rs) throws SQLException {
        /*  513 */     Calendar lTempban = Calendar.getInstance();
        /*  514 */     if (rs.getLong("tempban") == 0L) {
            /*  515 */       lTempban.setTimeInMillis(0L);
            /*  516 */       return lTempban;
                 }
        /*  518 */     Calendar today = Calendar.getInstance();
        /*  519 */     lTempban.setTimeInMillis(rs.getTimestamp("tempban").getTime());
        /*  520 */     if (today.getTimeInMillis() < lTempban.getTimeInMillis())
            /*  521 */       return lTempban;
        /*  523 */     lTempban.setTimeInMillis(0L);
        /*  524 */     return lTempban;
           }

       public Calendar getTempBanCalendar() {
        /*  528 */     return this.tempban;
           }

       public byte getBanReason() {
        /*  532 */     return this.greason;
           }

       public boolean hasBannedIP() {
        /*  536 */     boolean ret = false;
        /*  537 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  538 */         PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) {
            /*  539 */       ps.setString(1, getSessionIPAddress());
            /*  540 */       try (ResultSet rs = ps.executeQuery()) {
                /*  541 */         rs.next();
                /*  542 */         if (rs.getInt(1) > 0)
                    /*  543 */           ret = true;
                       }
            /*  547 */     } catch (SQLException ex) {
            /*  548 */       log.error("Error checking ip bans", ex);
                 }
        /*  550 */     return ret;
           }

       public String getMac() {
        /*  554 */     return this.mac;
           }

       public void setMac(String macData) {
        /*  558 */     if (macData.equalsIgnoreCase("00-00-00-00-00-00") || macData.length() != 17)
                   return;
        /*  561 */     this.mac = macData;
           }

       public boolean hasBannedMac() {
        /*  565 */     if (this.mac.equalsIgnoreCase("00-00-00-00-00-00") || this.mac.length() != 17)
            /*  566 */       return false;
        /*  568 */     boolean ret = false;
        /*  569 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  570 */         PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM macbans WHERE mac = ?")) {
            /*  571 */       ps.setString(1, this.mac);
            /*  572 */       try (ResultSet rs = ps.executeQuery()) {
                /*  573 */         rs.next();
                /*  574 */         if (rs.getInt(1) > 0)
                    /*  575 */           ret = true;
                       }
            /*  579 */     } catch (SQLException e) {
            /*  580 */       log.error("Error checking mac bans", e);
                 }
        /*  582 */     return ret;
           }

       public void banMacs() {
        /*  586 */     banMacs(this.mac);
           }

       public void banMacs(String macData) {
        /*  590 */     if (macData.equalsIgnoreCase("00-00-00-00-00-00") || macData.length() != 17)
                   return;
        /*  593 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  594 */         PreparedStatement ps = con.prepareStatement("INSERT INTO macbans (mac) VALUES (?)")) {
            /*  595 */       ps.setString(1, macData);
            /*  596 */       ps.executeUpdate();
            /*  598 */     } catch (SQLException e) {
            /*  599 */       log.error("Error banning MACs", e);
                 }
           }

       public void updateMacs() {
        /*  604 */     updateMacs(this.mac);
           }

       public void updateMacs(String macData) {
        /*  608 */     if (macData.equalsIgnoreCase("00-00-00-00-00-00") || macData.length() != 17)
                   return;
        /*  611 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  612 */         PreparedStatement ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?")) {
            /*  613 */       ps.setString(1, macData);
            /*  614 */       ps.setInt(2, this.accId);
            /*  615 */       ps.executeUpdate();
            /*  617 */     } catch (SQLException e) {
            /*  618 */       log.error("Error saving MACs", e);
                 }
           }

       public int finishLogin() {
        /*  629 */     login_mutex.lock();
             try {
            /*  631 */       byte state = getLoginState();
            /*  632 */       if (state > 0) {
                /*  633 */         this.loggedIn = false;
                /*  634 */         return 7;
                       }
            /*  636 */       updateLoginState(2, getSessionIPAddress());
                 } finally {
            /*  638 */       login_mutex.unlock();
                 }
        /*  640 */     return 0;
           }

       public void clearInformation() {
        /*  644 */     this.accountName = null;
        /*  645 */     this.accId = -1;
        /*  646 */     this.secondPassword = null;
        /*  647 */     this.salt2 = null;
        /*  648 */     this.gm = 0;
        /*  649 */     this.loggedIn = false;
        /*  650 */     this.mac = "00-00-00-00-00-00";
        /*  651 */     this.maclist.clear();
        /*  652 */     this.player = null;
           }

       public int changePassword(String oldpwd, String newpwd) {
        /*  656 */     int ret = -1;
        /*  657 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            /*  658 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE name = ?");
            /*  659 */       ps.setString(1, getAccountName());
            /*  660 */       ResultSet rs = ps.executeQuery();
            /*  661 */       if (rs.next()) {
                /*  662 */         boolean updatePassword = false;
                /*  663 */         String passhash = rs.getString("password");
                /*  664 */         String salt = rs.getString("salt");
                /*  665 */         if (passhash == null || passhash.isEmpty()) {
                    /*  666 */           ret = -1;
                    /*  667 */         } else if (LoginCryptoLegacy.isLegacyPassword(passhash) && LoginCryptoLegacy.checkPassword(oldpwd, passhash)) {
                    /*  668 */           ret = 0;
                    /*  669 */           updatePassword = true;
                    /*  670 */         } else if (oldpwd.equals(passhash)) {
                    /*  671 */           ret = 0;
                    /*  672 */           updatePassword = true;
                    /*  673 */         } else if (salt == null && LoginCrypto.checkSha1Hash(passhash, oldpwd)) {
                    /*  674 */           ret = 0;
                    /*  675 */           updatePassword = true;
                    /*  676 */         } else if (LoginCrypto.checkSaltedSha512Hash(passhash, oldpwd, salt)) {
                    /*  677 */           ret = 0;
                    /*  678 */           updatePassword = true;
                             } else {
                    /*  680 */           ret = -1;
                             }
                /*  682 */         if (updatePassword)
                    /*  683 */           try (PreparedStatement pss = con.prepareStatement("UPDATE `accounts` SET `password` = ?, `salt` = ? WHERE id = ?")) {
                        /*  684 */             String newSalt = LoginCrypto.makeSalt();
                        /*  685 */             pss.setString(1, LoginCrypto.makeSaltedSha512Hash(newpwd, newSalt));
                        /*  686 */             pss.setString(2, newSalt);
                        /*  687 */             pss.setInt(3, this.accId);
                        /*  688 */             pss.executeUpdate();
                                   }
                       }
            /*  692 */       ps.close();
            /*  693 */       rs.close();
            /*  694 */     } catch (SQLException e) {
            /*  695 */       log.error("修改游戏帐号密码出现错误.\r\n", e);
                 }
        /*  697 */     return ret;
           }

       public MapleEnumClass.AuthReply login(String login, String pwd, boolean ipMacBanned, boolean useKey) {
        /*  701 */     MapleEnumClass.AuthReply loginok = MapleEnumClass.AuthReply.GAME_ACCOUNT_NOT_LANDED;
        /*  702 */     if (!useKey) {
            /*  703 */       this.loginattempt = (byte)(this.loginattempt + 1);
            /*  704 */       if (this.loginattempt > 6) {
                /*  705 */         log.info("账号[" + login + "]登录次数达到6次还未登录游戏，服务端断开连接.");
                /*  706 */         getSession().close();
                       }
                 }
        /*  709 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  710 */         PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE name = ?")) {
            /*  711 */       ps.setString(1, login);
            /*  712 */       try (ResultSet rs = ps.executeQuery()) {
                /*  713 */         if (rs.next()) {
                    /*  714 */           int banned = rs.getInt("banned");
                    /*  715 */           String passhash = rs.getString("password");
                    /*  716 */           String salt = rs.getString("salt");
                    /*  717 */           String oldSession = rs.getString("SessionIP");
                    /*  719 */           this.accountName = login;
                    /*  720 */           this.accId = rs.getInt("id");
                    /*  721 */           this.secondPassword = rs.getString("2ndpassword");
                    /*  722 */           this.salt2 = rs.getString("salt2");
                    /*  723 */           this.gm = rs.getInt("gm");
                    /*  724 */           this.greason = rs.getByte("greason");
                    /*  725 */           this.tempban = getTempBanCalendar(rs);
                    /*  726 */           this.gender = rs.getByte("gender");
                    /*  728 */           this.maclist = new LinkedList<>();
                    /*  729 */           String macStrs = rs.getString("maclist");
                    /*  730 */           if (macStrs != null) {
                        /*  731 */             String[] macData = macStrs.split(",");
                        /*  732 */             for (String macData1 : macData) {
                            /*  733 */               if (macData1.length() == 17)
                                /*  734 */                 this.maclist.add(macData1);
                                         }
                                   }
                    /*  739 */           if (this.secondPassword != null && this.salt2 != null)
                        /*  740 */             this.secondPassword = LoginCrypto.rand_r(this.secondPassword);
                    /*  742 */           ps.close();
                    /*  744 */           if (useKey) {
                        /*  745 */             loginok = MapleEnumClass.AuthReply.GAME_LOGIN_SUCCESSFUL;
                        /*  747 */           } else if (banned > 0 && this.gm < 6) {
                        /*  748 */             loginok = MapleEnumClass.AuthReply.GAME_ACCOUNT_DELETE;
                                   } else {
                        /*  750 */             if (banned == -1)
                            /*  751 */               unban();
                        /*  753 */             boolean updatePasswordHash = false;
                        /*  755 */             if (passhash == null || passhash.isEmpty()) {
                            /*  757 */               if (oldSession != null && !oldSession.isEmpty()) {
                                /*  758 */                 this.loggedIn = getSessionIPAddress().equals(oldSession);
                                /*  759 */                 loginok = this.loggedIn ? MapleEnumClass.AuthReply.GAME_LOGIN_SUCCESSFUL : MapleEnumClass.AuthReply.GAME_PASSWORD_ERROR;
                                /*  760 */                 updatePasswordHash = this.loggedIn;
                                               } else {
                                /*  762 */                 loginok = MapleEnumClass.AuthReply.GAME_PASSWORD_ERROR;
                                /*  763 */                 this.loggedIn = false;
                                               }
                            /*  765 */             } else if (LoginCryptoLegacy.isLegacyPassword(passhash) && LoginCryptoLegacy.checkPassword(pwd, passhash)) {
                            /*  767 */               loginok = MapleEnumClass.AuthReply.GAME_LOGIN_SUCCESSFUL;
                            /*  768 */               updatePasswordHash = true;
                            /*  769 */             } else if (pwd.equals(passhash)) {
                            /*  770 */               loginok = MapleEnumClass.AuthReply.GAME_LOGIN_SUCCESSFUL;
                            /*  771 */               updatePasswordHash = true;
                            /*  772 */             } else if (salt == null && LoginCrypto.checkSha1Hash(passhash, pwd)) {
                            /*  773 */               loginok = MapleEnumClass.AuthReply.GAME_LOGIN_SUCCESSFUL;
                            /*  774 */               updatePasswordHash = true;
                            /*  775 */             } else if (LoginCrypto.checkSaltedSha512Hash(passhash, pwd, salt)) {
                            /*  776 */               loginok = MapleEnumClass.AuthReply.GAME_LOGIN_SUCCESSFUL;
                                         } else {
                            /*  778 */               this.loggedIn = false;
                            /*  779 */               loginok = MapleEnumClass.AuthReply.GAME_PASSWORD_ERROR;
                                         }
                        /*  781 */             if (updatePasswordHash && ServerConfig.LOGIN_USESHA1HASH)
                            /*  782 */               try (PreparedStatement pss = con.prepareStatement("UPDATE `accounts` SET `password` = ?, `salt` = ? WHERE id = ?")) {
                                /*  783 */                 String newSalt = LoginCrypto.makeSalt();
                                /*  784 */                 pss.setString(1, LoginCrypto.makeSaltedSha512Hash(pwd, newSalt));
                                /*  785 */                 pss.setString(2, newSalt);
                                /*  786 */                 pss.setInt(3, this.accId);
                                /*  787 */                 pss.executeUpdate();
                                               }
                        /*  790 */             if (ServerConfig.LOGIN_AUTOFIX) {
                            /*  791 */               log_autofix.info("[自动解卡] 账号:" + login);
                            /*  792 */               if (getLoginState() > 0) {
                                /*  793 */                 this.loggedIn = false;
                                /*  794 */                 if (loginok == MapleEnumClass.AuthReply.GAME_LOGIN_SUCCESSFUL) {
                                    /*  795 */                   loginok = MapleEnumClass.AuthReply.GAME_CONNECTING_ACCOUNT;
                                    /*  796 */                   boolean find = (WorldFindService.getInstance().findCharacterByAccId(this.accId) != null);
                                    /*  797 */                   if (getLoginState() == 2 && !find)
                                        /*  798 */                     try (PreparedStatement pse = con.prepareStatement("UPDATE accounts SET loggedin = 0 WHERE name = ?")) {
                                            /*  799 */                       pse.setString(1, this.accountName);
                                            /*  800 */                       pse.executeUpdate();
                                                                 }
                                                     }
                                /*  804 */                 clearInformation();
                                               }
                                         }
                                   }
                             } else {
                                            if (AutoRegister.createAccount(login, pwd)) {
                                                loginok = login(login, pwd, ipMacBanned, useKey);
                                            }
                                        }
                       }
            /*  812 */     } catch (SQLException e) {
            /*  813 */       log.error("登录游戏帐号出现错误. 账号: " + login + " \r\n", e);
                 }
        /*  815 */     return loginok;
           }

       public void 登录账号断开在线角色(int AccId) {
        /*  819 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            /*  820 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM `characters` WHERE `accountid` = ?");
            /*  821 */       ps.setInt(1, AccId);
            /*  822 */       ResultSet rs = ps.executeQuery();
            /*  823 */       while (rs.next()) {
                /*  824 */         for (ChannelServer cservs : ChannelServer.getAllInstances()) {
                    /*  825 */           MapleCharacter player = cservs.getPlayerStorage().getCharacterById(rs.getInt("id"));
                    /*  826 */           if (player != null) {
                        /*  827 */             System.out.println("重复登录账号断开在线角色[" + player.getName() + "]");
                        /*  829 */             player.getClient().disconnect(true, false);
                        /*  830 */             player.getClient().getSession().close();
                                   }
                             }
                       }
            /*  834 */     } catch (SQLException e) {
            /*  835 */       System.err.println("重复登录账号断开在线角色失败" + e);
                 }
           }

       public boolean CheckSecondPassword(String in) {
        /*  841 */     boolean allow = false;
        /*  842 */     boolean updatePasswordHash = false;
        /*  844 */     if (LoginCryptoLegacy.isLegacyPassword(this.secondPassword) && LoginCryptoLegacy.checkPassword(in, this.secondPassword)) {
            /*  846 */       allow = true;
            /*  847 */       updatePasswordHash = true;
            /*  848 */     } else if (this.salt2 == null && LoginCrypto.checkSha1Hash(this.secondPassword, in)) {
            /*  849 */       allow = true;
            /*  850 */       updatePasswordHash = true;
            /*  851 */     } else if (LoginCrypto.checkSaltedSha512Hash(this.secondPassword, in, this.salt2)) {
            /*  852 */       allow = true;
                 }
        /*  854 */     if (updatePasswordHash)
            /*  855 */       return updateSecondPassword();
        /*  857 */     return allow;
           }

       private void unban() {
        /*  861 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  862 */         PreparedStatement ps = con.prepareStatement("UPDATE accounts SET banned = 0, banreason = '' WHERE id = ?")) {
            /*  863 */       ps.setInt(1, this.accId);
            /*  864 */       ps.executeUpdate();
            /*  866 */     } catch (SQLException e) {
            /*  867 */       log.error("Error while unbanning", e);
                 }
           }

       public int getAccID() {
        /*  872 */     return this.accId;
           }

       public void setAccID(int id) {
        /*  876 */     this.accId = id;
           }

       public void updateLoginState(int newstate) {
        /*  880 */     updateLoginState(newstate, getSessionIPAddress());
           }

       public void updateLoginState(int newstate, String SessionID) {
        /*  884 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  885 */         PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = ?, SessionIP = ?, lastlogin = CURRENT_TIMESTAMP() WHERE id = ?")) {
            /*  886 */       ps.setInt(1, newstate);
            /*  887 */       ps.setString(2, SessionID);
            /*  888 */       ps.setInt(3, getAccID());
            /*  889 */       ps.executeUpdate();
            /*  891 */     } catch (SQLException e) {
            /*  892 */       log.error("Error updating login state", e);
                 } finally {
            /*  894 */       if (newstate == 0) {
                /*  895 */         this.loggedIn = false;
                /*  896 */         this.serverTransition = false;
                       } else {
                /*  898 */         this.serverTransition = (newstate == 1 || newstate == 3);
                /*  899 */         this.loggedIn = !this.serverTransition;
                       }
                 }
           }

       public boolean updateSecondPassword() {
        /*  905 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /*  906 */         PreparedStatement ps = con.prepareStatement("UPDATE `accounts` SET `2ndpassword` = ?, `salt2` = ? WHERE id = ?")) {
            /*  907 */       String newSalt = LoginCrypto.makeSalt();
            /*  908 */       ps.setString(1, LoginCrypto.rand_s(LoginCrypto.makeSaltedSha512Hash(this.secondPassword, newSalt)));
            /*  909 */       ps.setString(2, newSalt);
            /*  910 */       ps.setInt(3, this.accId);
            /*  911 */       ps.executeUpdate();
            /*  912 */       return true;
            /*  914 */     } catch (SQLException e) {
            /*  915 */       return false;
                 }
           }

       public byte getLoginState() {
        try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            try (PreparedStatement ps = con.prepareStatement("SELECT loggedin, lastlogin, banned, `birthday` + 0 AS `bday` FROM accounts WHERE id = ?")) {
                ps.setInt(1, getAccID());
                try (ResultSet rs = ps.executeQuery()) {
                    if (!rs.next() || rs.getInt("banned") > 0) {
                        session.close();
                        log.error("Account doesn't exist or is banned");
                        return MapleClient.LOGIN_NOTLOGGEDIN;
                    }
                    birthday = rs.getInt("bday");
                    byte state = rs.getByte("loggedin");

                    /*
                     * 如果是在更换频道或者登录过渡
                     * 检测 lastlogin 的时间加 20秒 小于当前系统的时间
                     * 就更新登录状态为 0
                     */
                    if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.CHANGE_CHANNEL) {
                        if (rs.getTimestamp("lastlogin").getTime() + 20000 < System.currentTimeMillis()) { // connecting to chanserver timeout
                            state = MapleClient.LOGIN_NOTLOGGEDIN;
                            updateLoginState(state, getSessionIPAddress());
                        }
                    }
                    loggedIn = state == MapleClient.LOGIN_LOGGEDIN;
                    return state;
                }
            }
        } catch (SQLException e) {
            loggedIn = false;
            log.error("error getting login state", e);
            return MapleClient.LOGIN_NOTLOGGEDIN;
        }
           }

       public boolean checkBirthDate(int date) {
        /*  955 */     return (this.birthday == date);
           }

       public void removalTask(boolean shutdown) {
             try {
            /*  960 */       this.player.cancelAllBuffs_();
            /*  961 */       this.player.cancelAllDebuffs();
            /*  962 */       if (this.player.getMarriageId() > 0) {
                /*  963 */         MapleQuestStatus stat1 = this.player.getQuestNoAdd(MapleQuest.getInstance(160001));
                /*  964 */         MapleQuestStatus stat2 = this.player.getQuestNoAdd(MapleQuest.getInstance(160002));
                /*  965 */         if (stat1 != null && stat1.getCustomData() != null && (stat1.getCustomData().equals("2_") || stat1.getCustomData().equals("2"))) {
                    /*  967 */           if (stat2 != null && stat2.getCustomData() != null)
                        /*  968 */             stat2.setCustomData("0");
                    /*  970 */           stat1.setCustomData("3");
                             }
                       }
            /*  973 */       if (this.player.getMapId() == 180000001 && !this.player.isIntern()) {
                /*  974 */         MapleQuestStatus stat1 = this.player.getQuestNAdd(MapleQuest.getInstance(123455));
                /*  975 */         MapleQuestStatus stat2 = this.player.getQuestNAdd(MapleQuest.getInstance(123456));
                /*  976 */         if (stat1.getCustomData() == null) {
                    /*  977 */           stat1.setCustomData(String.valueOf(System.currentTimeMillis()));
                    /*  978 */         } else if (stat2.getCustomData() == null) {
                    /*  979 */           stat2.setCustomData("0");
                             } else {
                    /*  981 */           int seconds = Integer.parseInt(stat2.getCustomData()) - (int)((System.currentTimeMillis() - Long.parseLong(stat1.getCustomData())) / 1000L);
                    /*  982 */           if (seconds < 0)
                        /*  983 */             seconds = 0;
                    /*  985 */           stat2.setCustomData(String.valueOf(seconds));
                             }
                       }
            /*  988 */       this.player.changeRemoval(true);
            /*  989 */       if (this.player.getEventInstance() != null)
                /*  990 */         this.player.getEventInstance().playerDisconnected(this.player, this.player.getId());
            /*  992 */       IMaplePlayerShop shop = this.player.getPlayerShop();
            /*  993 */       if (shop != null) {
                /*  994 */         shop.removeVisitor(this.player);
                /*  995 */         if (shop.isOwner(this.player))
                    /*  996 */           if (shop.getShopType() == 1 && shop.isAvailable() && !shutdown) {
                        /*  997 */             shop.setOpen(true);
                                   } else {
                        /*  999 */             shop.closeShop(true, !shutdown);
                                   }
                       }
            /* 1003 */       this.player.setMessenger(null);
            /* 1004 */       if (this.player.getAntiMacro().inProgress())
                /* 1005 */         this.player.getAntiMacro().end();
            /* 1007 */       if (this.player.getMap() != null) {
                /* 1008 */         if (shutdown || (getChannelServer() != null && getChannelServer().isShutdown())) {
                    /* 1009 */           int questID = -1;
                    /* 1010 */           switch (this.player.getMapId()) {
                                     case 240060200:
                            /* 1012 */               questID = 160100;
                                           break;
                                     case 240060201:
                            /* 1015 */               questID = 160103;
                                           break;
                                     case 280030000:
                                         case 280030100:
                            /* 1019 */               questID = 160101;
                                           break;
                                     case 280030001:
                            /* 1022 */               questID = 160102;
                                           break;
                                     case 270050100:
                            /* 1025 */               questID = 160104;
                                           break;
                                     case 105100300:
                                         case 105100400:
                            /* 1029 */               questID = 160106;
                                           break;
                                     case 211070000:
                                         case 211070100:
                                         case 211070101:
                                         case 211070110:
                            /* 1035 */               questID = 160107;
                                           break;
                                     case 551030200:
                            /* 1038 */               questID = 160108;
                                           break;
                                     case 271040100:
                            /* 1041 */               questID = 160109;
                                           break;
                                   }
                    /* 1044 */           if (questID > 0)
                        /* 1045 */             this.player.getQuestNAdd(MapleQuest.getInstance(questID)).setCustomData("0");
                    /* 1047 */         } else if (this.player.isAlive()) {
                    /* 1048 */           switch (this.player.getMapId()) {
                                     case 220080001:
                                         case 541010100:
                                         case 541020800:
                            /* 1052 */               this.player.getMap().addDisconnected(this.player.getId());
                                           break;
                                   }
                             }
                /* 1056 */         this.player.getMap().removePlayer(this.player);
                       }
            /* 1058 */     } catch (Throwable e) {
            /* 1059 */       log.error(e);
                 }
           }

       public void disconnect(boolean RemoveInChannelServer, boolean fromCS) {
        /* 1064 */     disconnect(RemoveInChannelServer, fromCS, false);
           }

       public void disconnect(boolean RemoveInChannelServer, boolean fromCS, boolean shutdown) {
        /* 1068 */     if (this.player != null) {
            /* 1069 */       if (ServerConfig.CHANNEL_DUMMY_MODE && this.player.getGMLevel() == -1)
                         return;
            /* 1072 */       disconnect(RemoveInChannelServer, false, fromCS, shutdown);
                 }
        /* 1074 */     if (!this.serverTransition && isLoggedIn())
            /* 1075 */       updateLoginState(0, getSessionIPAddress());
        /* 1077 */     this.engines.clear();
        /* 1078 */     cancelPingtTask();
           }

       public void disconnect(boolean RemoveInChannelServer, boolean bl3, boolean fromCS, boolean shutdown) {
        /* 1206 */     if (this.debugWindow != null) {
            /* 1207 */       this.debugWindow.dispose();
            /* 1208 */       this.debugWindow = null;
                 }
        /* 1210 */     int idz = -1;
        /* 1211 */     ChannelServer ch = null;
        /* 1212 */     String namez = null;
        /* 1213 */     this.disconnectLock.writeLock().lock();
             try {
            /* 1215 */       if (this.isDisconnect && this.player == null)
                         return;
            /* 1218 */       this.isDisconnect = true;
            /* 1220 */       saveKeyValue();
            /* 1222 */       MapleMap map = this.player.getMap();
            /* 1223 */       ch = ChannelServer.getInstance((map == null) ? this.channel : map.getChannel());
            /* 1224 */       MapleParty party = this.player.getParty();
            /* 1225 */       namez = this.player.getName();
            /* 1226 */       idz = this.player.getId();
            /* 1227 */       int messengerId = (this.player.getMessenger() == null) ? 0 : this.player.getMessenger().getId(), gid = this.player.getGuildId(), fid = this.player.getFamilyId();
            /* 1228 */       BuddyList chrBuddy = this.player.getBuddylist();
            /* 1229 */       MaplePartyCharacter chrParty = new MaplePartyCharacter(this.player);
            /* 1230 */       MapleMessengerCharacter chrMessenger = new MapleMessengerCharacter(this.player);
            /* 1231 */       MapleGuildCharacter chrGuild = this.player.getMGC();
            /* 1232 */       MapleFamilyCharacter chrFamily = this.player.getMFC();
            /* 1233 */       removalTask(shutdown);
            /* 1234 */       LoginServer.getLoginAuth(this.player.getId());
            /* 1235 */       LoginServer.getLoginAuthKey(this.accountName, true);
            /* 1236 */       this.player.saveToDB(true, fromCS);
            /* 1237 */       if (shutdown) {
                /* 1238 */         this.player = null;
                /* 1239 */         this.receiving = false;
                         return;
                       }
            /* 1242 */       if (messengerId > 0)
                /* 1243 */         WorldMessengerService.getInstance().leaveMessenger(messengerId, chrMessenger);
            /* 1246 */       if (!fromCS) {
                /* 1247 */         if (party != null &&
                        /* 1248 */           !bl3) {
                    /* 1249 */           party.cancelAllPartyBuffsByChr(idz);
                    /* 1250 */           chrParty.setOnline(false);
                    /* 1251 */           WorldPartyService.getInstance().updateParty(party.getPartyId(), PartyOperation.LOG_ONOFF, chrParty);
                    /* 1252 */           if (map != null && party.getLeader().getId() == idz) {
                        /* 1253 */             MaplePartyCharacter lchr = null;
                        /* 1254 */             for (MaplePartyCharacter pchr : party.getMembers()) {
                            /* 1255 */               if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() < pchr.getLevel()))
                                /* 1256 */                 lchr = pchr;
                                         }
                        /* 1259 */             if (lchr != null)
                            /* 1260 */               WorldPartyService.getInstance().updateParty(party.getPartyId(), PartyOperation.CHANGE_LEADER_DC, lchr);
                                   }
                             }
                /* 1265 */         if (gid > 0 && chrGuild != null)
                    /* 1266 */           WorldGuildService.getInstance().setGuildMemberOnline(chrGuild, false, -1);
                /* 1268 */         if (fid > 0 && chrFamily != null)
                    /* 1269 */           WorldFamilyService.getInstance().setFamilyMemberOnline(chrFamily, false, -1);
                       }
            /* 1273 */       if (chrBuddy != null)
                /* 1274 */         if (!this.serverTransition) {
                    /* 1275 */           WorldBuddyService.getInstance().loggedOff(namez, idz, this.channel, chrBuddy.getBuddyIds());
                             } else {
                    /* 1277 */           WorldBuddyService.getInstance().loggedOn(namez, idz, this.channel, chrBuddy.getBuddyIds());
                             }
            /* 1280 */       if (fromCS)
                /* 1281 */         this.player.setMessenger(null);
            /* 1284 */     } catch (Exception e) {
            /* 1285 */       log.error("断开玩家失败", e);
                 } finally {
            /* 1287 */       this.engines.clear();
            /* 1288 */       if (RemoveInChannelServer && idz > 0 && namez != null)
                /* 1289 */         if (fromCS) {
                    /* 1290 */           CashShopServer.getPlayerStorage().deregisterPlayer(idz, namez, this.accId);
                             } else {
                    /* 1292 */           ch.getPlayerStorage().deregisterPlayer(idz, namez, this.accId);
                             }
            /* 1295 */       if (this.player != null) {
                /* 1296 */         this.player.setMap((MapleMap)null);
                /* 1297 */         this.player = null;
                       }
            /* 1300 */       this.disconnectLock.writeLock().unlock();
                 }
        /* 1302 */     cancelPingtTask();
           }

       private void saveKeyValue() throws SQLException {
        /* 1306 */     if (this.changed_keyValue)
            /* 1307 */       try(DruidPooledConnection conn = DatabaseConnection.getInstance().getConnection();
                    /* 1308 */           PreparedStatement ps = conn.prepareStatement("INSERT INTO accounts_keyvalue (`accountid`, `key`, `value`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)")) {
                /* 1309 */         ps.setInt(1, this.accId);
                /* 1310 */         for (Map.Entry<String, String> entry : this.keyValue.entrySet()) {
                    /* 1311 */           ps.setString(2, entry.getKey());
                    /* 1312 */           ps.setString(3, entry.getValue());
                    /* 1313 */           ps.executeUpdate();
                             }
                       }
           }

       public String getSessionIPAddress() {
        /* 1321 */     if (this.session == null || !this.session.isActive())
            /* 1322 */       return "0.0.0.0";
        /* 1324 */     return this.session.remoteAddress().toString().split(":")[0];
           }

       public boolean CheckIPAddress() {
        /* 1328 */     if (this.accId < 0)
            /* 1329 */       return false;
        /* 1331 */     boolean canlogin = true;
        /* 1332 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
            /* 1333 */       PreparedStatement ps = con.prepareStatement("SELECT SessionIP, banned FROM accounts WHERE id = ?");
            /* 1334 */       ps.setInt(1, this.accId);
            /* 1335 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1336 */         if (rs.next() &&
                        /* 1337 */           rs.getInt("banned") > 0)
                    /* 1338 */           canlogin = false;
                       }
            /* 1342 */     } catch (SQLException e) {
            /* 1343 */       log.error("Failed in checking IP address for client.", e);
                 }
        /* 1345 */     return canlogin;
           }

       public void DebugMessage(StringBuilder sb) {
        /* 1349 */     sb.append(getSession().remoteAddress());
        /* 1350 */     sb.append(" 是否连接: ");
        /* 1351 */     sb.append(getSession().isActive());
        /* 1352 */     sb.append(" 是否断开: ");
        /* 1353 */     sb.append(!getSession().isOpen());
        /* 1354 */     sb.append(" 密匙状态: ");
        /* 1355 */     sb.append((getSession().attr(CLIENT_KEY) != null));
        /* 1356 */     sb.append(" 登录状态: ");
        /* 1357 */     sb.append(isLoggedIn());
        /* 1358 */     sb.append(" 是否有角色: ");
        /* 1359 */     sb.append((getPlayer() != null));
           }

       public int getChannel() {
        /* 1363 */     return this.channel;
           }

       public void setChannel(int channel) {
        /* 1367 */     this.channel = channel;
           }

       public ChannelServer getChannelServer() {
        /* 1371 */     return ChannelServer.getInstance(this.channel);
           }

       public int deleteCharacter(int cid) {
        /* 1375 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1376 */         PreparedStatement ps = con.prepareStatement("SELECT guildid, guildrank, familyid, name FROM characters WHERE id = ? AND accountid = ?")) {
            /* 1377 */       ps.setInt(1, cid);
            /* 1378 */       ps.setInt(2, this.accId);
            /* 1379 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1380 */         if (!rs.next()) {
                    /* 1381 */           rs.close();
                    /* 1382 */           ps.close();
                    /* 1383 */           return 1;
                             }
                /* 1385 */         if (rs.getInt("guildid") > 0) {
                    /* 1386 */           if (rs.getInt("guildrank") == 1) {
                        /* 1387 */             rs.close();
                        /* 1388 */             ps.close();
                        /* 1389 */             return 1;
                                   }
                    /* 1391 */           WorldGuildService.getInstance().deleteGuildCharacter(rs.getInt("guildid"), cid);
                             }
                /* 1393 */         if (rs.getInt("familyid") > 0 && WorldFamilyService.getInstance().getFamily(rs.getInt("familyid")) != null)
                    /* 1394 */           WorldFamilyService.getInstance().getFamily(rs.getInt("familyid")).leaveFamily(cid);
                       }
            /* 1398 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM characters WHERE id = ?", cid);
            /* 1399 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "UPDATE pokemon SET active = 0 WHERE characterid = ?", cid);
            /* 1400 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM hiredmerch WHERE characterid = ?", cid);
            /* 1401 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM mts_cart WHERE characterid = ?", cid);
            /* 1402 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM mts_items WHERE characterid = ?", cid);
            /* 1403 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM cheatlog WHERE characterid = ?", cid);
            /* 1404 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM mountdata WHERE characterid = ?", cid);
            /* 1405 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM inventoryitems WHERE characterid = ?", cid);
            /* 1406 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM famelog WHERE characterid = ?", cid);
            /* 1407 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM famelog WHERE characterid_to = ?", cid);
            /* 1408 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM dueypackages WHERE RecieverId = ?", cid);
            /* 1409 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM wishlist WHERE characterid = ?", cid);
            /* 1410 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM buddies WHERE characterid = ?", cid);
            /* 1411 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM buddies WHERE buddyid = ?", cid);
            /* 1412 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM keymap WHERE characterid = ?", cid);
            /* 1413 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM trocklocations WHERE characterid = ?", cid);
            /* 1414 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM savedlocations WHERE characterid = ?", cid);
            /* 1415 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM skills WHERE characterid = ?", cid);
            /* 1416 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM skills WHERE teachId = ?", cid);
            /* 1417 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM familiars WHERE characterid = ?", cid);
            /* 1418 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM mountdata WHERE characterid = ?", cid);
            /* 1419 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM skillmacros WHERE characterid = ?", cid);
            /* 1420 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM queststatus WHERE characterid = ?", cid);
            /* 1421 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM inventoryslot WHERE characterid = ?", cid);
            /* 1422 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM extendedSlots WHERE characterid = ?", cid);
            /* 1423 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM bank WHERE charid = ?", cid);
            /* 1424 */       MapleCharacter.deleteWhereCharacterId((Connection)con, "DELETE FROM bosslog WHERE characterid = ?", cid);
            /* 1425 */       return 0;
            /* 1427 */     } catch (SQLException e) {
            /* 1428 */       log.error("删除角色错误.", e);
            /* 1430 */       return 1;
                 }
           }

       public byte getGender() {
        /* 1434 */     return this.gender;
           }

       public void setGender(byte gender) {
        /* 1438 */     this.gender = gender;
        /* 1439 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1440 */         PreparedStatement ps = con.prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) {
            /* 1441 */       ps.setByte(1, gender);
            /* 1442 */       ps.setInt(2, this.accId);
            /* 1443 */       ps.executeUpdate();
            /* 1444 */       ps.close();
            /* 1446 */     } catch (SQLException e) {
            /* 1447 */       log.error("保存角色性别出错", e);
                 }
           }

       public String getSecondPassword() {
        /* 1452 */     return this.secondPassword;
           }

       public void setSecondPassword(String secondPassword) {
        /* 1456 */     this.secondPassword = secondPassword;
           }

       public String getAccountName() {
        /* 1460 */     return this.accountName;
           }

       public void setAccountName(String accountName) {
        /* 1464 */     this.accountName = accountName;
           }

       public int getWorld() {
        /* 1468 */     return this.world;
           }

       public void setWorld(int world) {
        /* 1472 */     this.world = world;
           }

       public int getLatency() {
        /* 1476 */     return (int)(this.lastPong - this.lastPing);
           }

       public int getChatServerLatency() {
        /* 1480 */     return (int)(this.lastChatServerPong - 0L);
           }

       public long getLastPong() {
        /* 1484 */     return this.lastPong;
           }

       public long getLastChatServerPong() {
        /* 1488 */     return this.lastChatServerPong;
           }

       public long getLastPing() {
        /* 1492 */     return this.lastPing;
           }

       public long getLastChatServerPing() {
        /* 1496 */     return 0L;
           }

       public void pongReceived() {
        /* 1500 */     this.timeoutCount = 0;
        /* 1501 */     this.lastPong = System.currentTimeMillis();
           }

       public void chatServerPongReceived() {
        /* 1505 */     this.lastChatServerPong = System.currentTimeMillis();
           }

       public void sendPing(boolean inChannel) {
        lastPing = System.currentTimeMillis();
        session.writeAndFlush(LoginPacket.getPing(inChannel));
//        session.writeAndFlush(LoginPacket.getChatServerPing());

        Timer.PingTimer.getInstance().schedule(() -> {
            try {
                if (getLatency() < 0) {
                    disconnect(true, false);
                    boolean close = false;
                    if (getSession() != null && getSession().isActive()) {
                        close = true;
                        getSession().close();
                    }
                    log.info(getLogMessage(MapleClient.this, "自动断线 : Ping超时" + (close ? "。" : ".")));
                }
            } catch (NullPointerException e) {
                System.out.println(e.toString());
            }
        }, 60000);
           }

       public void cancelPingtTask() {
        /* 1551 */     if (this.pingTask != null) {
            /* 1552 */       this.pingTask.cancel(true);
            /* 1553 */       this.pingTask = null;
                 }
           }

       public boolean isGm() {
        /* 1558 */     return (this.gm > 0);
           }

       public int getGmLevel() {
        /* 1562 */     return this.gm;
           }

       public ScheduledFuture<?> getIdleTask() {
        /* 1566 */     return this.idleTask;
           }

       public void setIdleTask(ScheduledFuture<?> idleTask) {
        /* 1570 */     this.idleTask = idleTask;
           }

       public int getAccCharSlots() {
        /* 1577 */     if (this.charslots != ServerConfig.CHANNEL_PLAYER_MAXCHARACTERS)
            /* 1578 */       return this.charslots;
        /* 1580 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1581 */         PreparedStatement ps = con.prepareStatement("SELECT * FROM character_slots WHERE accid = ? AND worldid = ?")) {
            /* 1582 */       ps.setInt(1, this.accId);
            /* 1583 */       ps.setInt(2, this.world);
            /* 1584 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1585 */         if (rs.next()) {
                    /* 1586 */           this.charslots = rs.getInt("charslots");
                             } else {
                    /* 1588 */           try (PreparedStatement psu = con.prepareStatement("INSERT INTO character_slots (accid, worldid, charslots) VALUES (?, ?, ?)")) {
                        /* 1589 */             psu.setInt(1, this.accId);
                        /* 1590 */             psu.setInt(2, this.world);
                        /* 1591 */             psu.setInt(3, this.charslots);
                        /* 1592 */             psu.executeUpdate();
                                   }
                             }
                       }
            /* 1597 */     } catch (SQLException e) {
            /* 1598 */       log.error("获取帐号可创建角色数量出现错误", e);
                 }
        /* 1600 */     return this.charslots;
           }

       public boolean gainAccCharSlot() {
        /* 1607 */     if (getAccCharSlots() >= 49)
            /* 1608 */       return false;
        /* 1610 */     this.charslots++;
        /* 1611 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1612 */         PreparedStatement ps = con.prepareStatement("UPDATE character_slots SET charslots = ? WHERE worldid = ? AND accid = ?")) {
            /* 1613 */       ps.setInt(1, this.charslots);
            /* 1614 */       ps.setInt(2, this.world);
            /* 1615 */       ps.setInt(3, this.accId);
            /* 1616 */       ps.executeUpdate();
            /* 1617 */       return true;
            /* 1619 */     } catch (SQLException e) {
            /* 1620 */       log.error("增加帐号可创建角色数量出现错误", e);
            /* 1621 */       return false;
                 }
           }

       public int getAccCardSlots() {
        /* 1629 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1630 */         PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts_info WHERE accId = ? AND worldId = ?")) {
            /* 1631 */       ps.setInt(1, this.accId);
            /* 1632 */       ps.setInt(2, this.world);
            /* 1633 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1634 */         if (rs.next()) {
                    /* 1635 */           this.cardslots = rs.getInt("cardSlots");
                             } else {
                    /* 1637 */           try (PreparedStatement psu = con.prepareStatement("INSERT INTO accounts_info (accId, worldId, cardSlots) VALUES (?, ?, ?)")) {
                        /* 1638 */             psu.setInt(1, this.accId);
                        /* 1639 */             psu.setInt(2, this.world);
                        /* 1640 */             psu.setInt(3, this.cardslots);
                        /* 1641 */             psu.executeUpdate();
                                   }
                             }
                       }
            /* 1646 */     } catch (SQLException e) {
            /* 1647 */       log.error("获取帐号下的角色卡数量出现错误", e);
                 }
        /* 1649 */     return this.cardslots;
           }

       public boolean gainAccCardSlot() {
        /* 1656 */     if (getAccCardSlots() >= 9)
            /* 1657 */       return false;
        /* 1659 */     this.cardslots++;
        /* 1660 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1661 */         PreparedStatement ps = con.prepareStatement("UPDATE accounts_info SET cardSlots = ? WHERE worldId = ? AND accId = ?")) {
            /* 1662 */       ps.setInt(1, this.cardslots);
            /* 1663 */       ps.setInt(2, this.world);
            /* 1664 */       ps.setInt(3, this.accId);
            /* 1665 */       ps.executeUpdate();
            /* 1666 */       return true;
            /* 1668 */     } catch (SQLException e) {
            /* 1669 */       log.error("增加角色卡的数量出现错误", e);
            /* 1670 */       return false;
                 }
           }

       public boolean isMonitored() {
        /* 1675 */     return this.monitored;
           }

       public void setMonitored(boolean m) {
        /* 1679 */     this.monitored = m;
           }

       public boolean isReceiving() {
        /* 1683 */     return this.receiving;
           }

       public void setReceiving(boolean m) {
        /* 1687 */     this.receiving = m;
           }

       public String getTempIP() {
        /* 1691 */     return this.tempIP;
           }

       public void setTempIP(String s) {
        /* 1695 */     this.tempIP = s;
           }

       public boolean isLocalhost() {
        /* 1699 */     return ServerConstants.isIPLocalhost(getSessionIPAddress());
           }

       public boolean hasCheck(int accid) {
        /* 1703 */     boolean ret = false;
        /* 1704 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1705 */         PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?")) {
            /* 1706 */       ps.setInt(1, accid);
            /* 1707 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1708 */         if (rs.next())
                    /* 1709 */           ret = (rs.getInt("check") > 0);
                       }
            /* 1713 */     } catch (SQLException e) {
            /* 1714 */       log.error("Error checking ip Check", e);
                 }
        /* 1716 */     return ret;
           }

       public void setScriptEngine(String name, ScriptEngine e) {
        /* 1720 */     this.engines.put(name, e);
           }

       public ScriptEngine getScriptEngine(String name) {
        /* 1724 */     return this.engines.get(name);
           }

       public void removeScriptEngine(String name) {
        /* 1728 */     this.engines.remove(name);
           }

       public boolean canClickNPC() {
        /* 1732 */     return (this.lastNpcClick + 500L < System.currentTimeMillis());
           }

       public void setClickedNPC() {
        /* 1736 */     this.lastNpcClick = System.currentTimeMillis();
           }

       public void removeClickedNPC() {
        /* 1740 */     this.lastNpcClick = 0L;
           }

       public NPCConversationManager getCM() {
        /* 1744 */     return NPCScriptManager.getInstance().getCM(this);
           }

       public QuestActionManager getQM() {
        /* 1748 */     return QuestScriptManager.getInstance().getQM(this);
           }

       public ItemActionManager getIM() {
        /* 1752 */     return ItemScriptManager.getInstance().getIM(this);
           }

       public boolean hasCheckMac(String macData) {
        /* 1756 */     return (!macData.equalsIgnoreCase("00-00-00-00-00-00") && macData.length() == 17 && !this.maclist.isEmpty() && this.maclist.contains(macData));
           }

       public void setTempInfo(String login, String pwd, boolean isBanned) {
        /* 1760 */     this.tempinfo = new Triple(login, pwd, Boolean.valueOf(isBanned));
           }

       public Triple<String, String, Boolean> getTempInfo() {
        /* 1764 */     return this.tempinfo;
           }

       public void addProcessName(String process) {
        /* 1768 */     this.proesslist.add(process);
           }

       public boolean hasProcessName(String process) {
        /* 1772 */     for (String p : this.proesslist) {
            /* 1773 */       if (p.startsWith(process))
                /* 1774 */         return true;
                 }
        /* 1777 */     return this.proesslist.contains(process);
           }

       public void dropMessage(String message) {
        /* 1781 */     announce(MaplePacketCreator.serverNotice(1, message));
           }

       public void modifyCSPoints(int type, int quantity) {
        /* 1785 */     switch (type) {
                   case 1:
                /* 1787 */         if (getACash() + quantity < 0)
                               return;
                /* 1790 */         setACash(getACash() + quantity);
                         break;
                   case 2:
                /* 1793 */         if (getMaplePoints() + quantity < 0)
                               return;
                /* 1796 */         setMaplePoints(getMaplePoints() + quantity);
                         break;
                 }
           }

       public int getCSPoints(int type) {
        /* 1804 */     switch (type) {
                   case 1:
                /* 1806 */         return getACash();
                   case 2:
                /* 1808 */         return getMaplePoints();
                 }
        /* 1810 */     return 0;
           }

       public int getACash() {
        /* 1815 */     int point = 0;
        /* 1816 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1817 */         PreparedStatement ps = con.prepareStatement("SELECT ACash FROM accounts WHERE name = ?")) {
            /* 1818 */       ps.setString(1, getAccountName());
            /* 1819 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1820 */         if (rs.next())
                    /* 1821 */           point = rs.getInt("ACash");
                       }
            /* 1825 */     } catch (SQLException e) {
            /* 1826 */       log.error("获取角色点券失败。" + e);
                 }
        /* 1828 */     return point;
           }

       public void setACash(int point) {
        /* 1832 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1833 */         PreparedStatement ps = con.prepareStatement("UPDATE accounts SET ACash = ? WHERE name = ?")) {
            /* 1834 */       ps.setInt(1, point);
            /* 1835 */       ps.setString(2, getAccountName());
            /* 1836 */       ps.executeUpdate();
            /* 1838 */     } catch (SQLException e) {
            /* 1839 */       log.error("获取角色点券失败。" + e);
                 }
           }

       public int getMaplePoints() {
        /* 1844 */     int point = 0;
        /* 1845 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1846 */         PreparedStatement ps = con.prepareStatement("SELECT mPoints FROM accounts WHERE id = ?")) {
            /* 1847 */       ps.setInt(1, getAccID());
            /* 1848 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1849 */         if (rs.next())
                    /* 1850 */           point = rs.getInt("mPoints");
                       }
            /* 1854 */     } catch (SQLException ex) {
            /* 1855 */       log.error("获取角色抵用券失败。" + ex);
                 }
        /* 1857 */     return point;
           }

       public void setMaplePoints(int point) {
        /* 1861 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1862 */         PreparedStatement ps = con.prepareStatement("UPDATE accounts SET mPoints = ? WHERE id = ?")) {
            /* 1863 */       ps.setInt(1, point);
            /* 1864 */       ps.setInt(2, getAccID());
            /* 1865 */       ps.executeUpdate();
            /* 1867 */     } catch (SQLException e) {
            /* 1868 */       log.error("获取角色抵用券失败。" + e);
                 }
           }

       public Map<String, String> getAccInfoFromDB() {
        /* 1873 */     Map<String, String> ret = new HashMap<>();
        /* 1874 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection();
                /* 1875 */         PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?")) {
            /* 1876 */       ps.setInt(1, this.accId);
            /* 1877 */       try (ResultSet rs = ps.executeQuery()) {
                /* 1878 */         ResultSetMetaData metaData = rs.getMetaData();
                /* 1879 */         if (rs.next())
                    /* 1880 */           for (int i = 1; i <= metaData.getColumnCount(); i++) {
                        /* 1881 */             String result = "";
                        /* 1885 */             result = rs.getString(metaData.getColumnName(i));
                        /* 1888 */             ret.put(metaData.getColumnName(i), result);
                                   }
                       }
            /* 1893 */     } catch (SQLException e) {
            /* 1894 */       log.error("获取帐号数据失败", e);
                 }
        /* 1896 */     return ret;
           }

       protected static class CharNameAndId {
             public final String name;

             public final int id;

             public CharNameAndId(String name, int id) {
            /* 1907 */       this.name = name;
            /* 1908 */       this.id = id;
                 }
           }

       public byte[] 初始化DesKey(int[] bytes, int 角色ID) {
        /* 1914 */     byte[] aKey = new byte[24];
        /* 1915 */     String sCharacterID = String.valueOf(角色ID);
        /* 1925 */     String sKey = String.valueOf("M@PleStoryMaPLe!");
        /* 1926 */     for (int i = 0; i < sKey.length(); i++)
            /* 1927 */       aKey[i] = (byte)sKey.charAt(i);
        /* 1930 */     System.arraycopy(aKey, 0, aKey, 16, 8);
        /* 1932 */     List<Integer> aUsed = new ArrayList<>();
        /* 1933 */     String sOpcode = "";
        /* 1934 */     int j = RecvPacketOpcode.BEGIN_USER.getValue() + 1;
        /* 1936 */     for (int x = RecvPacketOpcode.BEGIN_USER.getValue() + 1; x < 6000; x++) {
            /* 1938 */       int nNum = x;
            /* 1939 */       while (aUsed.contains(Integer.valueOf(nNum)))
                /* 1941 */         nNum = Randomizer.rand(RecvPacketOpcode.BEGIN_USER.getValue(), 9999);
            /* 1945 */       String sNum = String.format("%04d", new Object[] { Integer.valueOf(nNum) });
            /* 1946 */       if (!aUsed.contains(Integer.valueOf(nNum))) {
                /* 1947 */         this.mEncryptedOpcode.put(Integer.valueOf(nNum), Integer.valueOf(j));
                /* 1948 */         aUsed.add(Integer.valueOf(nNum));
                /* 1949 */         sOpcode = sOpcode + sNum;
                       }
            /* 1951 */       j++;
                 }
        /* 1953 */     aUsed.clear();
        /* 1954 */     TripleDESCipher pCipher = new TripleDESCipher(aKey);
             try {
            /* 1956 */       byte[] aBuffer = new byte[32768];
            /* 1957 */       byte[] aEncrypt = pCipher.Encrypt(sOpcode.getBytes());
            /* 1958 */       System.arraycopy(aEncrypt, 0, aBuffer, 0, aEncrypt.length);
            /* 1959 */       for (int k = aEncrypt.length; j < aBuffer.length; j++)
                /* 1960 */         aBuffer[j] = (byte)(int)Math.random();
            /* 1963 */       announce(MaplePacketCreator.OnOpcodeEncryption(4, aBuffer));
            /* 1964 */     } catch (Exception e) {
            /* 1965 */       e.printStackTrace();
                 }
        /* 1967 */     return aKey;
           }

       public Map<String, String> getKeyValue_Map() {
        /* 1971 */     return this.keyValue;
           }

       public String getKeyValueIfAbsent(String key, String value) {
        /* 1975 */     String v = this.keyValue.get(key);
        /* 1976 */     if (v == null) {
            /* 1977 */       v = this.keyValue.put(key, value);
            /* 1978 */       this.changed_keyValue = true;
                 }
        /* 1980 */     return v;
           }

       public String getKeyValue(String key) {
        /* 1984 */     if (this.keyValue.containsKey(key))
            /* 1985 */       return this.keyValue.get(key);
        /* 1987 */     return null;
           }

       public void setKeyValue(String key, String values) {
        /* 1991 */     this.keyValue.put(key, values);
        /* 1992 */     this.changed_keyValue = true;
           }

       public MapleClient() {}
     }


/* Location:              D:\MapleStory\maplerServer\zdms\Server_bakpwd.jar!\client\MapleClient.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */